package com.it.rabbitmqwithjiang.Config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


//发布订阅模式的配置,包括两个队列和对应的订阅者,发布者的交换机类型使用fanout(子网广播),两根网线binding用来绑定队列到交换机
@Configuration
public class FanoutConfig {
	/*
	  type=fanout  ------>fanoutqueue1------>C1
	 P--> X-------  binging
	               ------>fanoutqueue2------>C2

	* */

	@Bean
	public FanoutExchange fanoutExchange(){
		FanoutExchange fanoutExchange=new FanoutExchange("fanout");
		return fanoutExchange;
	}

 	@Bean
    public Queue myFanoutQueue1() {
       Queue queue=new Queue("fanoutqueue1");
       return queue;
    }
 	
 	@Bean
    public Queue myFanoutQueue2() {
       Queue queue=new Queue("fanoutqueue2");
       return queue;
    }

 	@Bean
 	public Binding binding1(){
 		Binding binding=BindingBuilder.bind(myFanoutQueue1()).to(fanoutExchange());
 		return binding;
 	}
 	
 	@Bean
 	public Binding binding2(){
 		Binding binding=BindingBuilder.bind(myFanoutQueue2()).to(fanoutExchange());
 		return binding;
 	}
 	
}
